
import 'dart:math';

import 'package:flutter/material.dart';

void main() =>runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return MaterialApp(
        home:HYHomePage()
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return Scaffold(
      appBar: AppBar(
        title: Text("列表测试"),
      ),
      body:GridViewDemo2()
    );
  }
}

class GridViewDemo2 extends StatelessWidget {
  const GridViewDemo2({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return GridView(
      gridDelegate:SliverGridDelegateWithMaxCrossAxisExtent(
          maxCrossAxisExtent: 220,
         crossAxisSpacing: 8,
        mainAxisSpacing: 8,
        childAspectRatio: 1.8,
      ),
      children: List.generate(100, (index){
        return Container(
          color: Color.fromARGB(255,Random().nextInt(256),Random().nextInt(256),Random().nextInt(256)),
        );
      }),
    );
  }
}

class GridViewDemo1 extends StatelessWidget {
  const GridViewDemo1({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: GridView(
          gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 4,
            childAspectRatio: 1,
            crossAxisSpacing: 8,
            mainAxisSpacing: 8
          ),
          children: List.generate(1000, (index){
            return Container(
              color: Color.fromARGB(255,Random().nextInt(256),Random().nextInt(256),Random().nextInt(256)),
            );
          }),
      ),
    );
  }
}





